package com.demo.ribbon;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;

/**
 * 自定义 Ribbon 负载均衡规则配置类
 *
 * @author YT
 * @date 2019-05-13
 */
@Configurable
@ExcludeComponentScan
public class RibbonConfiguration {

    /**
     * 定义 Ribbon 的负载均衡规则为随机访问
     * 默认的规则是服务提供者轮询访问
     *
     * @return
     */
    @Bean
    public IRule iRule(){
        return new RoundRobinRule();
    }
}
